home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-06-17 | 5.5 KB | 154 lines | [TEXT/dosa] |
- // DesktopMenuBar.java : this is a Java source code file for the program Facade.
- // Copyright 1998, Andrew S. Downs
- // andrew.downs@tulane.edu
- //
- // This source code is distributed as freeware.
- // Just keep this author information in the file. Enjoy!
-
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import java.util.*;
-
- public class DesktopMenuBar extends DesktopComponent implements Serializable/*, MouseListener*/ {
- int activeMenuId;
- Color highlightColor;
- Vector vector;
-
- DesktopMenuBar() {
- super();
- this.setFont( new Font( "Dialog", Font.BOLD, 12 ) );
- this.setHighlightColor( Global.menuBarHighlightColor );
- vector = new Vector();
- // this.addMouseListener( this );
- // this.addMouseMotionListener( this );
- }
-
- public void setActiveMenuId( int i ) {
- this.activeMenuId = i;
- }
-
- public int getActiveMenuId() {
- return this.activeMenuId;
- }
-
- public void setHighlightColor( Color c ) {
- this.highlightColor = c;
- }
-
- public Color getHighlightColor() {
- return this.highlightColor;
- }
-
- public void setVector( Vector v ) {
- this.vector = v;
- }
-
- public Vector getVector() {
- return this.vector;
- }
-
- public void paint( Graphics g ) {
- // Draw menubar.
- g.setColor( Color.white );
- g.fillRect( this.getX(), this.getY(), this.getWidth(), this.getHeight() );
- }
- /*
- public void mouseClicked( MouseEvent e ) {
- }
-
- public void mouseEntered( MouseEvent e ) {
- }
-
- public void mouseExited( MouseEvent e ) {
- }
-
- public void mouseReleased( MouseEvent e ) {
- }
-
- public void mousePressed( MouseEvent e ) {
- // New click means no previous selection.
- // this.activeMenu = -1;
- // this.activeMenuItem = -1;
-
- Graphics g = this.getGraphics();
- FontMetrics theFontMetrics = g.getFontMetrics();
-
- if ( this.contains( e.getX(), e.getY() ) ) {
- System.out.println( "Click in menubar." );
-
- // Handle menu selection.
- for ( int i = 0; i < dmb.getVector().size(); i++ ) {
- // Get menu object.
- DesktopMenu d = ( DesktopMenu )dmb.getVector().elementAt( i );
-
- // Determine if we're inside this menu.
- if ( ( e.getX() >= d.getX() - Global.defaultMenuHSep ) && ( e.getX() <= ( d.getX() + ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + Global.defaultMenuHSep ) )
- && ( e.getY() >= this.getY() ) && ( e.getY() <= this.getMenuBarHeight() ) ) {
- // Draw menubar highlighting.
- g.setColor( Color.blue );
- // g.fillRect( d.getX() - Global.defaultMenuHSep, this.getY(), ( d.getLabel() == null ? d.getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + ( 2 * Global.defaultMenuHSep ), getMenuBarHeight() );
- activeMenuRect = new Rectangle( d.getX() - Global.defaultMenuHSep, this.getY(), ( d.getLabel() == null ? ( ( DesktopImageMenu )d ).getImage().getWidth( this ) : theFontMetrics.stringWidth( d.getLabel() ) ) + ( 2 * Global.defaultMenuHSep ), getMenuBarHeight() );
- g.fillRect( activeMenuRect.x, activeMenuRect.y, activeMenuRect.width, activeMenuRect.height );
-
- // Draw menu String or Image.
- g.setColor( Color.black );
- if ( d.getLabel() != null )
- g.drawString( d.getLabel(), d.getX(), d.getY() );
- else
- g.drawImage( ( ( DesktopImageMenu )d ).getImage(), d.getX(), d.getY(), this );
-
- // Get menu item vector.
- Vector v = d.getVector();
-
- DesktopMenuItem dmi = ( DesktopMenuItem )v.elementAt( 0 );
- if ( dmi.getLabel().equals( Global.menuItemEmptyTrash ) ) {
- DesktopImage di = ( ( DesktopImage )this.vectorImages.elementAt( 1 ) );
- String path = di.getPath();
- File f = new File( path, Global.trashDisplayString );
- if ( f.exists() ) {
- String array[] = f.list();
-
- if ( array == null || array.length == 0 )
- dmi.setEnabled( false );
- else
- dmi.setEnabled( true );
- }
- }
-
- // Draw menu background.
- g.setColor( dmb.getBackground() );
- g.fillRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
-
- // Draw menu items.
- for ( int j = 0; j < v.size(); j++ ) {
- if ( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel().equals( Global.menuSep ) ) {
- g.setColor( Color.lightGray );
- g.fillRect( d.getItemBounds().getBounds().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getBounds().y + Global.defaultMenuItemVSep, d.getItemBounds().getBounds().width, 2 );
- continue;
- }
-
- g.setColor( Color.black );
- if ( !( ( DesktopMenuItem )v.elementAt( j ) ).getEnabled() )
- g.setColor( Color.lightGray );
- g.drawString( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( j ) ).getDrawPoint().y );
- }
-
- g.setColor( Color.black );
- g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );
- g.fillRect( d.getItemBounds().getBounds().x + 2, d.getItemBounds().getBounds().y + d.getItemBounds().getBounds().height, d.getItemBounds().getBounds().width, 2 );
- g.fillRect( d.getItemBounds().getBounds().x + d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().y + 2, 2, d.getItemBounds().getBounds().height );
-
- // Set current menu.
- this.activeMenu = i;
-
- // Once found, we're done.
- break;
- }
- }
- }
- }
- */
- }
-
-